<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use DB;
use App\Models\Squad;
use App\Models\Crouse;
use App\Models\Classroom;
use App\Models\Notice;
use App\Models\Crousesheet;
use App\Models\Term;


class Auto_make_jiaxiao_notice extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'auto_make_jiaxiao_notice';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $term_start_date = Term::where('status','0')->value('start_date');
        $zhou = ceil((time()-strtotime($term_start_date))/3600/24/7)-1;
        $date = date('Y-m-d H:i:s',strtotime("-7 days"));
        $squad_ids = Squad::all()->pluck('id')->toArray();
        //dd($squad_ids);
        for ($i=0; $i < count($squad_ids); $i++) { 
            $squad_id = $squad_ids[$i];
            $squad_name = Squad::where('id',$squad_id)->value('name');
            $tutor = Squad::where('id',$squad_id)->value('class_teacher');
        
            $jiaxiao_data[] = [
                'notice_type' =>'3',
                'event' =>'录入家校【第'.$zhou.'周】！【班级：'.$squad_name.'】',
                'starttime' =>$date,
                'grace_days'=>'15',
                'endtime' =>date('Y-m-d H:i:s',strtotime('+15 day',strtotime($date))),
                'status'=>'1',
                'squad_id'=>$squad_id,
                'tutor_id'=>$tutor
            ];
            // $zuoye_data[] = [
            //     'notice_type' =>'5',
            //     'event' =>'录入作业【第'.$zhou.'周】！【班级：'.$squad_name.'】',
            //     'starttime' =>$date,
            //     'grace_days'=>'15',
            //     'endtime' =>date('Y-m-d H:i:s',strtotime('+15 day',strtotime($date))),
            //     'status'=>'1',
            //     'squad_id'=>$squad_id,
            //     'tutor_id'=>$tutor
            // ];
        }
        
        $jiaxiao_res = Notice::insert($jiaxiao_data);
        //$zuoye_res = Notice::insert($zuoye_data);
    }
}
